package functions;


public class Cos extends Term {
	private Function function;

	public Cos(double coff, double exp, Function poly)
	{
		this.function = poly;
		this.coff = coff;
		this.expon = exp;
	}

	@Override
	public double eval(double x)
	{
		return Math.pow(coff * Math.cos(function.eval(x)), expon);
	}

	@Override
	public FunctionIF diff()
	{
		if(expon == 0)
			return new PolynTerm(1 , 0);
		
		Function p = (Function)function.clone();
		Sin diff = new Sin(1, 1, p);

		FunctionIF d_function = function.diff();
		return returnDerivative(diff, d_function);
	}

	@Override
	protected Object clone()
	{
		return new Cos(coff, expon, (Function) function.clone());
	}

	@Override
	public String toString()
	{
		if(expon == 1)
			return coff+"*cos(" + function.toString() + ")";
		else
			return coff+"*cos(" + function.toString() + ")^"+expon;
	}
}
